/*
 * @Author: 汪军 624473119@qq.com
 * @Date: 2023-10-20 09:12:03
 * @LastEditors: 汪军 624473119@qq.com
 * @LastEditTime: 2023-10-20 10:23:09
 * @FilePath: \ekee-web\src\permission.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// 路由鉴权
import router from "@/router/index.js";
// import store from './store'
// import { Message } from 'element-ui'
import { getToken } from "@/utils/auth"; // 验权

const whiteList = ["/login", "/home", "/register",'/agreement']; // 不重定向白名单
router.beforeEach((to, from, next) => {
  if (getToken()) {
    if (to.path === "/login") {
      if (window._hmt) {
        window._hmt.push(["_trackPageview", "/#" + to.fullPath]);
      }
      next({ path: "/login" });
    } else {
      next();
    }
  } else {
    // 没有token 去白名单路由
    if (whiteList.indexOf(to.path) !== -1) {
      next();
    } else {
      // 没有白名单 没有token 就去login
      // next('/login')
      next();
    }
  }
});
